package top.fzqblog.firstapp;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import top.fzqblog.fragment.FriendFragment;
import top.fzqblog.fragment.MsgFragment;
import top.fzqblog.fragment.fragment1;

/**
 * Created by 抽离 on 2017/8/18 0018.
 */

public class DynamicFragmentTest extends Activity {

    @BindView(R.id.btn_msgBtn)
    public TextView btn_msgBtn;

    @BindView(R.id.btn_friendBtn)
    public TextView btn_friendBtn;

    @OnClick({R.id.btn_msgBtn, R.id.btn_friendBtn})
    public void fragBtnClick(TextView view){
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        switch (view.getId()){
            case R.id.btn_msgBtn:
                clearSelected();
                btn_msgBtn.setBackgroundColor(Color.CYAN);
                transaction.replace(R.id.centerContent, msgFragment);
                transaction.commit();
                break;
            case R.id.btn_friendBtn:
                clearSelected();
                btn_friendBtn.setBackgroundColor(Color.CYAN);
                transaction.replace(R.id.centerContent, friendFragment);
                transaction.commit();
                break;
        }
    }

    public void clearSelected(){
        btn_msgBtn.setBackgroundColor(Color.rgb(235,237,244));
        btn_friendBtn.setBackgroundColor(Color.rgb(235,237,244));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dynamicfragment);
        ButterKnife.bind(this);
        msgFragment = new MsgFragment();
        friendFragment = new FriendFragment();
        setFragment();
    }

    MsgFragment msgFragment;

    FriendFragment friendFragment;
    public void setFragment(){
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        msgFragment = new MsgFragment();
        btn_msgBtn.setBackgroundColor(Color.CYAN);
        transaction.replace(R.id.centerContent, msgFragment);
        transaction.commit();
    }


}




